package com.qijian.maindata.controller;

import java.util.List;

import com.qijian.maindata.domain.ProductAttributeItemDetail;
import com.qijian.maindata.domain.dto.ProductAttributeItemDto;
import com.qijian.maindata.domain.query.ProductAttributeItemDetailQuery;
import com.qijian.maindata.service.IProductAttributeItemDetailService;
import com.qijian.maindata.service.IProductAttributeItemService;
import lombok.RequiredArgsConstructor;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qijian.common.annotation.Log;
import com.qijian.common.core.controller.BaseController;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.enums.BusinessType;
import com.qijian.common.utils.poi.ExcelUtil;
import com.qijian.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 辅助属性值详情Controller
 *
 * @author qijian
 * @date 2022-01-13
 */
@Api(tags = "辅助属性值详情")
@RestController
@RequiredArgsConstructor
@RequestMapping("/business/productAttributeItemDetail")
public class ProductAttributeItemDetailController extends BaseController {

    private final IProductAttributeItemService productAttributeItemService;
    private final IProductAttributeItemDetailService productAttributeItemDetailService;

    /**
     * 查询辅助属性值详情列表
     */
//    @PreAuthorize("@ss.hasPermi('business:productAttributeItemDetail:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(ProductAttributeItemDetailQuery query, IPage<ProductAttributeItemDetail> page) {
//        return getDataTable(productAttributeItemDetailService.page(Page.of(page.getCurrent(), page.getSize()), WhereEntityTool.invoke(query)));
//    }
    @PreAuthorize("@ss.hasPermi('maindata:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductAttributeItemDetailQuery query) {
//        ProductAttributeItem attrItem = productAttributeItemService.getByItemIdAttrId(query);
//        ProductAttributeItemDetailQuery q = new ProductAttributeItemDetailQuery();
//        q.setAttrItemId(attrItem.getId());
        return getDataTable(productAttributeItemDetailService.list(WhereEntityTool.invoke(query)));
    }

    /**
     * 导出辅助属性值详情列表
     */
    @PreAuthorize("@ss.hasPermi('maindata:item:export')")
    @Log(title = "辅助属性值详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(ProductAttributeItemDetailQuery query, HttpServletResponse response) {
        new ExcelUtil<>(ProductAttributeItemDetail.class).exportExcel(response, productAttributeItemDetailService.list(WhereEntityTool.invoke(query)), "辅助属性值详情数据");
    }

    /**
     * 获取辅助属性值详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('maindata:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productAttributeItemDetailService.getById(id));
    }

    /**
     * 新增辅助属性值详情
     */
    @PreAuthorize("@ss.hasPermi('maindata:item:add')")
    @Log(title = "辅助属性值详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductAttributeItemDetail productAttributeItemDetail) {
        return toAjax(productAttributeItemDetailService.save(productAttributeItemDetail));
    }

    @PreAuthorize("@ss.hasPermi('maindata:item:add')")
    @Log(title = "辅助属性值详情", businessType = BusinessType.INSERT)
    @PostMapping("saveUpdate")
    public AjaxResult saveUpdate(@RequestBody List<ProductAttributeItemDto> dto) {
        productAttributeItemDetailService.saveUpdate(dto);
        return AjaxResult.success();
    }

    /**
     * 修改辅助属性值详情
     */
    @PreAuthorize("@ss.hasPermi('maindata:item:edit')")
    @Log(title = "辅助属性值详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductAttributeItemDetail productAttributeItemDetail) {
        return toAjax(productAttributeItemDetailService.updateById(productAttributeItemDetail));
    }

    /**
     * 删除辅助属性值详情
     */
    @PreAuthorize("@ss.hasPermi('maindata:item:remove')")
    @Log(title = "辅助属性值详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(productAttributeItemDetailService.removeByIds(ids));
    }
}
